<!DOCTYPE html>
<html>
<head>
	<title></title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">	
	<meta name="viewport" content="width=device-width, initial-scale=1">	
	
	<script src="${_contextPath}/templates/freemarker/js/jquery-3.3.1.min.js"></script>
	<script src="${_contextPath}/templates/freemarker/js/jquery.lazyload.js"></script>	
	
	<script src="${_contextPath}/templates/freemarker/js/common.js"></script>
	
	<link href="${_contextPath}/templates/share/css/common.css" rel="stylesheet">
</head>
<body onload="init()">
	${imageTxt.content}
</body>
<script type="text/javascript">

var imgAll = document.getElementsByTagName("img");

$(document).ready(resetWidth());
function resetWidth(){
	for(var i=0;i<imgAll.length;i++){
		imgAll[i].style.width="100%";
		imgAll[i].style.maxWidth="100%";
		imgAll[i].style.marginLeft="0";
		
		let src = imgAll[i].src;
		if(src == "" || src == undefined){
			imgAll[i].src = "${_contextPath}/templates/freemarker/img/default.jpg";
		}
	}
	
	var videos = document.getElementsByTagName("video");
	for(video of videos){
		video.style.width = "100%";
	}
	
	var iframes = document.getElementsByTagName("iframe");
	for(iframe of iframes){
		iframe.width = "100%";
		iframe.height = "";
	}
}

function init(){
	$("img").lazyload();
	
	//创建数组
	let imageSrcArray = new Array();
	for(img of imgAll){
		if($(img).attr("data-original") == undefined){
			imageSrcArray.push(img.src);
		}else{
			imageSrcArray.push($(img).attr("data-original"));		
		}
	}
	
	for(var i=0;i<imgAll.length;i++){
		//添加事件	);
		let index = i;
		imgAll[i].addEventListener("click", function(){
			imageClick(imageSrcArray,index);
		});
	}
}

function imageClick(imageSrcArray,index){	
	var isAndroid = isAndroid_ios();
	if(isAndroid){
		window.toAndroid.openImages(index,JSON.stringify(imageSrcArray));
	}else{
		var newArray = new Array();
		newArray.push(index.toString());
		newArray = newArray.concat(imageSrcArray);
		window.webkit.messageHandlers.showMessage.postMessage(newArray);	
	}
}

function setImageHeight(){
	for(var i=0;i<imgAll.length;i++){
		var img_url = $(imgAll[i]).attr("data-original");
		if(img_url == undefined || img_url == "" ){
			continue;
		}
  
		let img = new Image();
		let idx = i;
		img.src = img_url;
		  
		img.onload = function(){
			let realHeight = this.height;
			let realWidth = this.width;
			let mobileWith = $(window).width();
			
			let calHeight = (realHeight/realWidth)*(mobileWith*0.96);
			$(imgAll[idx]).css("height",calHeight+"px");		
		};
	}
}
setTimeout(function(){
	$("img").lazyload();
	setImageHeight();
},700);
</script>
</html>